package org.springframework.boot;

import org.springframework.core.env.PropertySource;
import org.springframework.core.env.SimpleCommandLinePropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

/**
 * @ClassDescription:   创建environment对象
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/12/26 15:30
 */
public class Step3 {
    public static void main(String[] args) throws IOException {
        ApplicationEnvironment environment = new ApplicationEnvironment(); // 系统环境变量 ， properties , yaml
        environment.getPropertySources().addLast(new ResourcePropertySource(new ClassPathResource("application.properties")));
        environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));  // 命令行添加环境变量
        for (PropertySource<?> propertySource : environment.getPropertySources()) {
            System.out.println(propertySource);
        }
        System.out.println(environment.getProperty("JAVA_HOME"));
        System.out.println(environment.getProperty("server.port"));


    }
}
